﻿namespace DotNetCommon.Validate;

/// <summary>
/// 数字校验扩展
/// </summary>
public static class ValidateNumberExtensions
{
    #region 必须为正数(>0)
    /// <summary>
    /// 必须为正数
    /// </summary>
    public static IValidateContext<int?> MustGreaterThanZero(this IValidateContext<int?> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model == null || ctx.Model <= 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须为正数
    /// </summary>
    public static IValidateContext<int> MustGreaterThanZero(this IValidateContext<int> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model <= 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须为正数
    /// </summary>
    public static IValidateContext<uint?> MustGreaterThanZero(this IValidateContext<uint?> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model == null || ctx.Model <= 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须为正数
    /// </summary>
    public static IValidateContext<uint> MustGreaterThanZero(this IValidateContext<uint> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model <= 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须为正数
    /// </summary>
    public static IValidateContext<short?> MustGreaterThanZero(this IValidateContext<short?> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model == null || ctx.Model <= 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须为正数
    /// </summary>
    public static IValidateContext<short> MustGreaterThanZero(this IValidateContext<short> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model <= 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须为正数
    /// </summary>
    public static IValidateContext<ushort?> MustGreaterThanZero(this IValidateContext<ushort?> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model == null || ctx.Model <= 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须为正数
    /// </summary>
    public static IValidateContext<ushort> MustGreaterThanZero(this IValidateContext<ushort> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model <= 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须为正数
    /// </summary>
    public static IValidateContext<long?> MustGreaterThanZero(this IValidateContext<long?> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model == null || ctx.Model <= 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须为正数
    /// </summary>
    public static IValidateContext<long> MustGreaterThanZero(this IValidateContext<long> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model <= 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须为正数
    /// </summary>
    public static IValidateContext<ulong?> MustGreaterThanZero(this IValidateContext<ulong?> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model == null || ctx.Model <= 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须为正数
    /// </summary>
    public static IValidateContext<ulong> MustGreaterThanZero(this IValidateContext<ulong> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model <= 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须为正数
    /// </summary>
    public static IValidateContext<float?> MustGreaterThanZero(this IValidateContext<float?> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model == null || ctx.Model <= 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须为正数
    /// </summary>
    public static IValidateContext<float> MustGreaterThanZero(this IValidateContext<float> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model <= 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须为正数
    /// </summary>
    public static IValidateContext<double?> MustGreaterThanZero(this IValidateContext<double?> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model == null || ctx.Model <= 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须为正数
    /// </summary>
    public static IValidateContext<double> MustGreaterThanZero(this IValidateContext<double> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model <= 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须为正数
    /// </summary>
    public static IValidateContext<decimal?> MustGreaterThanZero(this IValidateContext<decimal?> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model == null || ctx.Model <= 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须为正数
    /// </summary>
    public static IValidateContext<decimal> MustGreaterThanZero(this IValidateContext<decimal> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model <= 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于 0 !");
        }
        return ctx;
    }
    #endregion

    #region 必须>=0
    /// <summary>
    /// 必须大于等于0
    /// </summary>
    public static IValidateContext<int?> MustGreaterThanOrEuqalToZero(this IValidateContext<int?> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model == null || ctx.Model < 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于等于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须大于等于0
    /// </summary>
    public static IValidateContext<int> MustGreaterThanOrEuqalToZero(this IValidateContext<int> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model < 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于等于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须大于等于0
    /// </summary>
    public static IValidateContext<short?> MustGreaterThanOrEuqalToZero(this IValidateContext<short?> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model == null || ctx.Model < 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于等于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须大于等于0
    /// </summary>
    public static IValidateContext<short> MustGreaterThanOrEuqalToZero(this IValidateContext<short> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model < 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于等于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须大于等于0
    /// </summary>
    public static IValidateContext<long?> MustGreaterThanOrEuqalToZero(this IValidateContext<long?> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model == null || ctx.Model < 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于等于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须大于等于0
    /// </summary>
    public static IValidateContext<long> MustGreaterThanOrEuqalToZero(this IValidateContext<long> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model < 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于等于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须大于等于0
    /// </summary>
    public static IValidateContext<float?> MustGreaterThanOrEuqalToZero(this IValidateContext<float?> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model == null || ctx.Model < 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于等于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须大于等于0
    /// </summary>
    public static IValidateContext<float> MustGreaterThanOrEuqalToZero(this IValidateContext<float> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model < 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于等于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须大于等于0
    /// </summary>
    public static IValidateContext<double?> MustGreaterThanOrEuqalToZero(this IValidateContext<double?> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model == null || ctx.Model < 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于等于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须大于等于0
    /// </summary>
    public static IValidateContext<double> MustGreaterThanOrEuqalToZero(this IValidateContext<double> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model < 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于等于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须大于等于0
    /// </summary>
    public static IValidateContext<decimal?> MustGreaterThanOrEuqalToZero(this IValidateContext<decimal?> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model == null || ctx.Model < 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于等于 0 !");
        }
        return ctx;
    }

    /// <summary>
    /// 必须大于等于0
    /// </summary>
    public static IValidateContext<decimal> MustGreaterThanOrEuqalToZero(this IValidateContext<decimal> ctx, string errorMessage = null)
    {
        if (ctx.StopValidate) return ctx;
        if (ctx.Model < 0)
        {
            ctx.AddError(ctx.ModelPath, errorMessage ?? $"'{ctx.ModelPath}' 必须大于等于 0 !");
        }
        return ctx;
    }
    #endregion
}
